-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathStartup.cs
245 lines (191 loc) · 17.2 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
using System;
using System.IO;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using NextGenSoftware.Logging;
using NextGenSoftware.OASIS.API.ONode.WebAPI.Filters;
using NextGenSoftware.OASIS.API.ONode.WebAPI.Interfaces;
using NextGenSoftware.OASIS.API.ONode.WebAPI.Middleware;
using NextGenSoftware.OASIS.API.ONode.WebAPI.Services;
using NextGenSoftware.OASIS.API.Providers.SOLANAOASIS.Infrastructure.Services.Solana;
using NextGenSoftware.OASIS.Common;
namespace NextGenSoftware.OASIS.API.ONode.WebAPI
{
public class Startup
{
private const string VERSION = "WEB 4 OASIS API v3.2.0";
//readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// If you wish to change the logging framework from the default (NLog) then set it below (or just change in OASIS_DNA - prefered way)
//LoggingManager.CurrentLoggingFramework = LoggingFramework.NLog;
//services.Configure<OASISSettings>(Configuration.GetSection("OASIS")); // Replaced by OASISConfigManager in OASISMiddleware so shares same codebase to STAR ODK.
// services.AddMvc();
// services.AddDbContext<DataContext>();
//services.AddCors(); //Needed twice? It is below too...
services.AddControllers(x => x.Filters.Add(typeof(ServiceExceptionInterceptor)))
.AddJsonOptions(x => x.JsonSerializerOptions.IgnoreNullValues = true);
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Contact = new OpenApiContact()
{
Email = "[email protected]",
Name = "OASIS API"
},
Description = "The OASIS API that powers Our World and the satillite apps/games/websites (OApp's/Moons) that plug into it. Check out <a target='_blank' href='https://drive.google.com/file/d/1nnhGpXcprr6kota1Y85HDDKsBfJHN6sn/view?usp=sharing'>The POWER Of The OASIS API</a> for more info.\n\nTo use the OASIS API follow these steps: \n\n <ol><li>First you need to create your avatar using the avatar/register method.</li><li>You will then receive an email to confirm your addrsss with a token. You then need to call the avatar/verify-email method with this token to verify and activate your new avatar.</li><li>Now you can call the avatar/authenticate method to login and authenticate. This will return your avatar object, which will contain a JWT (JSON Web Token) Security Token.</li><li>You can then set this in your HEADER for all future API calls. See descriptions below for each method for more details on how to use the OASIS API...</li></ol>\n\nYou will note that every request below has a corresponding overload that also takes a providerType. This allows you to overrite the default provider configured for the ONODE you are making the request from. The ONODE can be configured to have a list of default providers, which it will fail over to the next one if that provider goes down/is too slow, etc. It will automatically switch to the fastest provider available (and load balance between them) but if the overload is used it will override this default behaviour. Set the setGlobal flag to false if you wish to override only for that given request or to true if you wish to persist this override for all subsequent calls. The current list of providers supported are as follows (in order of priority used):\n\n<ul><li><b>MongoDBOASIS</b> - MongoDB Provider (Document/Object Database).</li><li><b>SQLLiteDBOASIS</b> - SQLLite Provider (Relational Database).</li><li><b>Neo4jOASIS</b> - Neo4j Provider (Graph Database).</li><li><b>HoloOASIS</b> - Holochain Provider.</li><li><b>SolanaOASIS </b> - Solana Provider.</li><li><b>EthereumOASIS</b> - Ethereum Provider.</li><li><b>EOSIOOASIS</b> - EOSIO Provider.</li><li><b>TelosOASIS</b> - Telos Provider.</li><li><b>SEEDSOASIS</b> - SEEDS Provider.</li><li><b>IPFSOASIS</b> - IPFS Provider.</li><li><b>AzureCosmosDBOASIS</b> - Azure COSMOS DB Provider (MS Cloud).</li></ul>\n\nSoon many more providers will be added such as ThreeFold, ActivityPub, SOLID, BlockStack & many more. Please check the github repo link below for more details... Soon HoloOASIS will be given top priority once hosting has been found for the Holochain Conductor (because the Holo Network is not yet live).\n\nThe Avatar (complete), half the Karma & half the Provider API's are currently implemented. The rest are coming soon... The SCMS (Smart Contract Management System) API's are completed but need to be refactored with some being removed so these also cannot be used currently. These are currently used for our first business use case, B.E.B (Built Enviroment Blockchain), a construction platform built on top of the OASIS API. More detailed documentation & future releases coming soon... \n\n<b>Please <a target='_blank' href='https://oasisplatform.world/postman/OASIS_API.postman_collection.json'>download the Postman JSON file</a> and import it into <a href='https://www.postman.com/' target='_blank'>Postman</a> if you wish to have a play/test and get familiar with the OASIS API before plugging it into your website/app/game/service.<br><br> You can download the Postman Dev Environment files below:<br><br><a target='_blank' href='https://oasisplatform.world/postman/OASIS_API_DEV.postman_environment.json'>Postman DEV Environment JSON</a><br><a target='_blank' href='https://oasisplatform.world/postman/OASIS_API_STAGING.postman_environment.json'>Postman STAGING Environment JSON</a><br><a target='_blank' href='https://oasisplatform.world/postman/OASIS_API_LIVE.postman_environment.json'>Postman LIVE Environment JSON</a><br>\n\nThis project is Open Source and if you have any feedback or better still, wish to get involved we would love to hear from you, please contact us on <a target='_blank' href='https://github.com/NextGenSoftwareUK/Our-World-OASIS-API-HoloNET-HoloUnity-And-.NET-HDK'>GitHub</a>, <a target='_blank' href='https://t.me/ourworldthegamechat'>Telegram</a>, <a target='_blank' href='https://discord.gg/RU6Z8YJ'>Discord</a> or using the <a href='mailto:[email protected]'>Contact</a> link below, we look forward to hearing from you...</b>\n\n<b>If you wish to receive FREE training on how to code and still get to help build a better world with us then please sign up at <a target='_blank' href='https://www.thejusticeleagueaccademy.icu/'>The Justice League Academy</a>. This is a superhero training platform that enables you to unleash your inner superhero and <b>FULL POTENTAL!</b> We <b>BELEIVE</b> in <b>YOU</b> and we will help you find your gift for the world...</b>\n\n<b>Check out the <a href='https://drive.google.com/file/d/1QPgnb39fsoXqcQx_YejdIhhoPbmSuTnF/view?usp=sharing' target='_blank'>DEV Plan/Roadmap</a> to see what has already been built and what is left to be built.</b>\n\n<b>Please join the <a target='_blank' href='https://t.me/oasisapihackalong'>OASIS API Weekly Hackalong Telegram Group</a> if you wish to get the latest news and developments as well as take part in weekly hackalongs where we can help you get up to speed ASAP.</b>\n\n<b>Please consider giving a <a target='_blank' href='http://www.gofundme.com/ourworldthegame'>donation</a> to help keep this vital project going... thank you.</b>\n\n\n\n<br><b><b>Want to make a difference in the world?\n\nWhat will be your legacy?\n\nReady to be a hero?</b>\n\n\n\n<br>Please come join the Our World Tribe on <a href='https://t.me/ourworldthegamechat'>Telegram</a> or <a href='https://discord.gg/q9gMKU6'>Discord.</a>, we look forward to seeing you there... :)</b><b><b>\n\nTOGETHER WE CAN CREATE A BETTER WORLD...</b></b>\n\n<br><a href='https://github.com/NextGenSoftwareUK/Our-World-OASIS-API-HoloNET-HoloUnity-And-.NET-HDK/blob/master/NextGenSoftware.OASIS.API.ONODE.WebAPI/OASIS%20API%20RELEASE%20HISTORY.md'>Release History</a>\n\n<a href='https://www.ourworldthegame.com/single-post/oasis-api-v0-0-1-altha-live'>v0.0.1 ALTHA</a>\n\n<br><b>Links</b>\n\n<a href='http://www.ourworldthegame.com'>http://www.ourworldthegame.com</a><br><a href='http://www.nextgensoftware.co.uk'>http://www.nextgensoftware.co.uk</a><br><a href='http://www.yoga4autism.com'>http://www.yoga4autism.com</a><br><a href='https://www.thejusticeleagueaccademy.icu/'>https://www.thejusticeleagueaccademy.icu/</a>\n\n<a href='https://github.com/NextGenSoftwareUK/Our-World-OASIS-API-HoloNET-HoloUnity-And-.NET-HDK'>https://github.com/NextGenSoftwareUK/Our-World-OASIS-API-HoloNET-HoloUnity-And-.NET-HDK</a><br><a href='http://www.gofundme.com/ourworldthegame'>http://www.gofundme.com/ourworldthegame</a>\n\n<a href='https://drive.google.com/file/d/1QPgnb39fsoXqcQx_YejdIhhoPbmSuTnF/view?usp=sharing'>DEV Plan/Roadmap</a><br><a href='https://drive.google.com/file/d/1nnhGpXcprr6kota1Y85HDDKsBfJHN6sn/view?usp=sharing'>The POWER Of The OASIS API</a><br>\n\n<a href='https://drive.google.com/file/d/1b_G08UTALUg4H3jPlBdElZAFvyRcVKj1/view?usp=sharing'>Join The Our World Tribe (Dev Requirements)</a><br><a href='https://drive.google.com/file/d/12pCk20iLw_uA1yIfojcP6WwvyOT4WRiO/view?usp=sharing'>The Our World Mission/Summary</a>\n\n<a href='http://www.facebook.com/ourworldthegame'>http://www.facebook.com/ourworldthegame</a><br><a href='http://www.twitter.com/ourworldthegame'>http://www.twitter.com/ourworldthegame</a><br><a href='https://www.youtube.com/channel/UC0_O4RwdY3lq1m3-K-njUxA'>https://www.youtube.com/channel/UC0_O4RwdY3lq1m3-K-njUxA</a>\n\n<a href='https://t.me/ourworldthegamechat'>https://t.me/ourworldthegamechat</a> (Telegram General Chat)<br><a href='https://t.me/ourworldthegame'>https://t.me/ourworldthegame</a> (Telegram Our World Annoucments)<br><a href='https://t.me/ourworldtechupdates'>https://t.me/ourworldtechupdates</a> (Telegram Our World Tech Updates)<br><a href='https://t.me/oasisapihackalong'>https://t.me/oasisapihackalong</a> OASIS API Weekly Hackalongs\n\n<a href='https://discord.gg/q9gMKU6'>https://discord.gg/q9gMKU6</a>",
Title = VERSION,
Version = "v1",
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
/*
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});*/
// configure strongly typed settings object
// services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
// configure DI for application services
services.AddScoped<IAvatarService, AvatarService>();
//services.AddScoped<IEmailService, EmailService>();
services.AddScoped<ISolanaService, SolanaService>(); //TODO: Not sure we need this? Want to remove this along with all other services ASAP! Use Managers in OASIS.API.Core and OASIS.API.ONode.Core instead!
//services.AddScoped<ICargoService, CargoService>();
//services.AddScoped<INftService, NftService>();
//services.AddScoped<IOlandService, OlandService>();
services.AddHttpContextAccessor();
//services.AddCors(options =>
//{
// options.AddPolicy(MyAllowSpecificOrigins,
// builder =>
// {
// builder.WithOrigins("https://localhost:44371").AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
// builder.WithOrigins("https://localhost").AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
// });
//});
// services.AddControllers();
//TODO: Don't think this is used anymore? Take out...
// configure basic authentication
// services.AddAuthentication("BasicAuthentication")
// .AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
//public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataContext context)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
LoggingManager.Log("Starting up The OASIS... (REST API)", LogType.Info);
LoggingManager.Log("Test Debug", LogType.Debug);
LoggingManager.Log("Test Info", LogType.Info);
LoggingManager.Log("Test Warning", LogType.Warning);
LoggingManager.Log("Test Error", LogType.Error);
// migrate database changes on startup (includes initial db creation)
//context.Database.Migrate();
// IApplicationBuilder app, IHostingEnvironment env)
//{
// app.UseDeveloperExceptionPage();
// app.UseStaticFiles();
// app.UseMvcWithDefaultRoute();
// }
// generated swagger json and swagger ui middleware
app.UseSwagger();
app.UseSwaggerUI(x => x.SwaggerEndpoint("/swagger/v1/swagger.json", VERSION));
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
// app.UseMvcWithDefaultRoute();
app.UseHttpsRedirection();
app.UseRouting();
//app.UseSession();
// global cors policy
app.UseCors(x => x
.SetIsOriginAllowed(origin => true)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
//TODO: Was this, check later...
//app.UseCors(MyAllowSpecificOrigins);
app.UseAuthorization();
app.UseMiddleware<OASISMiddleware>();
app.UseMiddleware<ErrorHandlerMiddleware>();
app.UseMiddleware<JwtMiddleware>();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
// string dbConn = configuration.GetSection("MySettings").GetSection("DbConnection").Value;
/*
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
//endpoints.MapControllerRoute(name: "phases",
// pattern: "phases/",
// //pattern: "phases/{*article}",
// defaults: new { controller = "SmartContractManagement", action = "GetAllPhases" });
});*/
}
}
}
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Threading.Tasks;
//using Microsoft.AspNetCore.Builder;
//using Microsoft.AspNetCore.Hosting;
//using Microsoft.AspNetCore.HttpsPolicy;
//using Microsoft.AspNetCore.Mvc;
//using Microsoft.Extensions.Configuration;
//using Microsoft.Extensions.DependencyInjection;
//using Microsoft.Extensions.Logging;
//using Microsoft.Extensions.Options;
//namespace NextGenSoftware.OASIS.API.ONode.WebAPI
//{
// public class Startup
// {
// public Startup(IConfiguration configuration)
// {
// Configuration = configuration;
// }
// public IConfiguration Configuration { get; }
// // This method gets called by the runtime. Use this method to add services to the container.
// public void ConfigureServices(IServiceCollection services)
// {
// services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// }
// // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
// public void Configure(IApplicationBuilder app, IHostingEnvironment env)
// {
// if (env.IsDevelopment())
// {
// app.UseDeveloperExceptionPage();
// }
// else
// {
// // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
// app.UseHsts();
// }
// app.UseHttpsRedirection();
// app.UseMvc();
// }
// }
//}