public static IOAuthClientFlow NewOAuthFlow(this IOAuthRemoteServerAccount account) { var session = EntityHelper.GetSession(account); var flow = session.NewEntity <IOAuthClientFlow>(); flow.Account = account; flow.Status = OAuthFlowStatus.Started; return(flow); }
public static OAuthAccount ToModel(this IOAuthRemoteServerAccount account) { if (account == null) { return(null); } return(new OAuthAccount() { Id = account.Id, AccountName = account.Name, Server = account.Server.Name }); }
public static IOAuthClientFlow BeginOAuthFlow(this IOAuthRemoteServerAccount account, Guid?userId = null, string scopes = null) { var session = EntityHelper.GetSession(account); var stt = session.GetOAuthSettings(); var flow = account.NewOAuthFlow(); if (string.IsNullOrEmpty(stt.RedirectUrl)) { AutoAssignRedirectUrl(stt, session.Context); } flow.UserId = userId; flow.Scopes = scopes ?? account.Server.Scopes; //all scopes flow.RedirectUrl = AdjustRedirectUrl(stt.RedirectUrl, account.Server.Options); var clientId = account.ClientIdentifier; flow.AuthorizationUrl = account.Server.AuthorizationUrl + StringHelper.FormatUri(OAuthClientModule.AuthorizationUrlQuery, clientId, flow.RedirectUrl, flow.Scopes, flow.Id.ToString()); return(flow); }
public static IOAuthAccessToken NewOAuthAccessToken(this IOAuthRemoteServerAccount account, Guid?userId, string accessToken, OAuthTokenType tokenType, string refreshToken, string openIdToken, string scopes, DateTime retrievedOn, DateTime expiresOn, string encryptionChannelName = null) { var session = EntityHelper.GetSession(account); var ent = session.NewEntity <IOAuthAccessToken>(); ent.Account = account; ent.UserId = userId; ent.AccessToken = accessToken; ent.TokenType = tokenType; if (!string.IsNullOrWhiteSpace(refreshToken)) { ent.RefreshToken = refreshToken; } //if (!string.IsNullOrWhiteSpace(openIdToken)) // ent.OpenIdToken = <Unpack Open Id token> ent.Scopes = scopes; ent.RetrievedOn = retrievedOn; ent.ExpiresOn = expiresOn; return(ent); }