Skip to content

Commit 99890b9

Browse files
committed
Changed Xamarin app authentication to Hybrid flow mode
2 parents ad4142b + 9d44a39 commit 99890b9

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

  • src
    • Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Identity
    • Services/Identity/Identity.API/Configuration

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Identity/IdentityService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ public string CreateAuthorizationRequest()
1414
// Dictionary with values for the authorize request
1515
var dic = new Dictionary<string, string>();
1616
dic.Add("client_id", "xamarin");
17-
dic.Add("response_type", "id_token token");
18-
dic.Add("scope", "openid profile basket orders");
17+
dic.Add("client_secret", "secret");
18+
dic.Add("response_type", "code id_token token");
19+
dic.Add("scope", "openid profile basket orders offline_access");
1920

2021
dic.Add("redirect_uri", GlobalSetting.Instance.IdentityCallback);
2122
dic.Add("nonce", Guid.NewGuid().ToString("N"));
@@ -24,7 +25,7 @@ public string CreateAuthorizationRequest()
2425
var currentCSRFToken = Guid.NewGuid().ToString("N");
2526
dic.Add("state", currentCSRFToken);
2627

27-
var authorizeUri = authorizeRequest.Create(dic);
28+
var authorizeUri = authorizeRequest.Create(dic);
2829
return authorizeUri;
2930
}
3031

src/Services/Identity/Identity.API/Configuration/Config.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using IdentityServer4.Models;
2-
using Microsoft.Extensions.Options;
1+
using IdentityServer4;
2+
using IdentityServer4.Models;
33
using System.Collections.Generic;
4-
using IdentityServer4;
54

65
namespace Identity.API.Configuration
76
{
@@ -56,19 +55,26 @@ public static IEnumerable<Client> GetClients(Dictionary<string,string> clientsUr
5655
{
5756
ClientId = "xamarin",
5857
ClientName = "eShop Xamarin OpenId Client",
59-
AllowedGrantTypes = GrantTypes.Implicit,
60-
AllowAccessTokensViaBrowser = true,
61-
RedirectUris = { clientsUrl["Xamarin"] },
58+
AllowedGrantTypes = GrantTypes.Hybrid,
59+
//Used to retrieve the access token on the back channel.
60+
ClientSecrets =
61+
{
62+
new Secret("secret".Sha256())
63+
},
64+
RedirectUris = { clientsUrl["Xamarin"] },
6265
RequireConsent = false,
6366
PostLogoutRedirectUris = { $"{clientsUrl["Xamarin"]}/Account/Redirecting" },
64-
AllowedCorsOrigins = { "http://eshopxamarin" },
65-
AllowedScopes =
67+
AllowedCorsOrigins = { "http://eshopxamarin" },
68+
AllowedScopes = new List<string>
6669
{
6770
IdentityServerConstants.StandardScopes.OpenId,
6871
IdentityServerConstants.StandardScopes.Profile,
72+
IdentityServerConstants.StandardScopes.OfflineAccess,
6973
"orders",
7074
"basket"
71-
}
75+
},
76+
//Allow requesting refresh tokens for long lived API access
77+
AllowOfflineAccess = true
7278
},
7379
new Client
7480
{
@@ -96,7 +102,7 @@ public static IEnumerable<Client> GetClients(Dictionary<string,string> clientsUr
96102
IdentityServerConstants.StandardScopes.Profile,
97103
IdentityServerConstants.StandardScopes.OfflineAccess,
98104
"orders",
99-
"basket",
105+
"basket"
100106
},
101107
}
102108
};

0 commit comments

Comments
 (0)