Skip to content

Commit caa75d5

Browse files
committed
added the ability to obtain the access token for api calls.
1 parent f6ba3de commit caa75d5

4 files changed

Lines changed: 81 additions & 5 deletions

File tree

admin/TwoWeeksReady.Admin/App.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
public TokenProvider InitialState { get; set; }
2929

3030
protected override void OnInitialized()
31-
{
32-
Service.AccessToken = InitialState.AccessToken;
33-
base.OnInitialized();
34-
}
31+
{
32+
Service.AccessToken = InitialState.AccessToken;
33+
base.OnInitialized();
34+
}
3535
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using TwoWeeksReady.Admin.Security;
6+
using TwoWeeksReady.Common.EmergencyKits;
7+
8+
namespace TwoWeeksReady.Admin.Data
9+
{
10+
public class FunctionsRepository : IRepository
11+
{
12+
private TokenProvider _tokenProvider;
13+
14+
public FunctionsRepository(TokenProvider tokenProvider)
15+
{
16+
this._tokenProvider = tokenProvider;
17+
}
18+
public Task<IEnumerable<BaseKit>> GetAllBaseKits()
19+
{
20+
throw new NotImplementedException();
21+
}
22+
23+
public Task<IEnumerable<HazardHunt>> GetAllHazardHunts()
24+
{
25+
throw new NotImplementedException();
26+
}
27+
28+
public Task<IEnumerable<HazardInfo>> GetAllHazardInfos()
29+
{
30+
throw new NotImplementedException();
31+
}
32+
33+
public Task<BaseKit> GetBaseKitById(string id)
34+
{
35+
throw new NotImplementedException();
36+
}
37+
38+
public Task<HazardHunt> GetHazardHuntById(string id)
39+
{
40+
throw new NotImplementedException();
41+
}
42+
43+
public Task<HazardInfo> GetHazardInfoById(string id)
44+
{
45+
throw new NotImplementedException();
46+
}
47+
48+
public Task<BaseKitItem> SaveBaseKitItem(BaseKitItem kit)
49+
{
50+
throw new NotImplementedException();
51+
}
52+
53+
public Task<HazardHunt> SaveHazardHunt(HazardHunt hazardHunt)
54+
{
55+
throw new NotImplementedException();
56+
}
57+
58+
public Task<HazardInfo> SaveHazardInfo(HazardInfo hazardInfo)
59+
{
60+
throw new NotImplementedException();
61+
}
62+
}
63+
}

admin/TwoWeeksReady.Admin/Pages/_Host.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</head>
2222

2323
<body>
24-
@{
24+
@{
2525
var token = new TokenProvider
2626
{
2727
AccessToken = await HttpContext.GetTokenAsync("access_token")

admin/TwoWeeksReady.Admin/Startup.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void ConfigureServices(IServiceCollection services)
5656

5757
options.Scope.Clear();
5858
options.Scope.Add("openid");
59+
options.Scope.Add("profile");
5960

6061
options.CallbackPath = new PathString("/callback");
6162
options.ClaimsIssuer = "Auth0";
@@ -68,6 +69,17 @@ public void ConfigureServices(IServiceCollection services)
6869

6970
options.Events = new OpenIdConnectEvents
7071
{
72+
OnRedirectToIdentityProvider = context =>
73+
{
74+
// The context's ProtocolMessage can be used to pass along additional query parameters
75+
// to Auth0's /authorize endpoint.
76+
//
77+
// Set the audience query parameter to the API identifier to ensure the returned Access Tokens can be used
78+
// to call protected endpoints on the corresponding API.
79+
context.ProtocolMessage.SetParameter("audience", Configuration["Auth0:Audience"]);
80+
81+
return Task.FromResult(0);
82+
},
7183
OnRedirectToIdentityProviderForSignOut = (context) =>
7284
{
7385
var logoutUri = $"https://{Configuration["Auth0:Domain"]}/v2/logout?client_id={Configuration["Auth0:ClientId"]}";
@@ -94,6 +106,7 @@ public void ConfigureServices(IServiceCollection services)
94106
services.AddHttpContextAccessor();
95107
services.AddScoped<TokenProvider>();
96108
services.AddScoped<IRepository, StubRepository>();
109+
//services.AddScoped<IRepository, FunctionsRepository>();
97110
}
98111

99112
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

0 commit comments

Comments
 (0)