Ejemplo n.º 1
0
        public static IOAuthExternalUser FindUser(this IOAuthRemoteServer server, string externalUserId)
        {
            var session = EntityHelper.GetSession(server);
            var user    = session.EntitySet <IOAuthExternalUser>().Where(u => u.Server == server && u.ExternalUserId == externalUserId).FirstOrDefault();

            return(user);
        }
Ejemplo n.º 2
0
 public static string[] GetScopes(this IOAuthRemoteServer server)
 {
     if (string.IsNullOrWhiteSpace(server.Scopes))
     {
         return new string[] { }
     }
     ;
     return(server.Scopes.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
 }
Ejemplo n.º 3
0
        public static IOAuthExternalUser NewExternalUser(this IOAuthRemoteServer server, Guid userId, string externalUserId)
        {
            var session = EntityHelper.GetSession(server);
            var user    = session.NewEntity <IOAuthExternalUser>();

            user.Server         = server;
            user.UserId         = userId;
            user.ExternalUserId = externalUserId;
            return(user);
        }
Ejemplo n.º 4
0
        public static IOAuthRemoteServerAccount NewOAuthAccount(this IOAuthRemoteServer server,
                                                                string clientIdentifier, string clientSecret,
                                                                string accountName, Guid?ownerId = null, string encryptionChannelName = null)
        {
            var session = EntityHelper.GetSession(server);
            var acct    = session.NewEntity <IOAuthRemoteServerAccount>();

            acct.Server           = server;
            acct.Name             = accountName;
            acct.ClientIdentifier = clientIdentifier;
            acct.ClientSecret     = clientSecret;
            return(acct);
        }
Ejemplo n.º 5
0
        // A primitive way of finding user id inside json, by finding property by name (specified in IOAuthRemoteServer) and extracting its value,
        // without converting Json into strongly typed object
        public static string ExtractUserId(this IOAuthRemoteServer server, string profileJson)
        {
            if (string.IsNullOrWhiteSpace(server.ProfileUserIdTag))
            {
                return(null);
            }
            var qtag   = '"' + server.ProfileUserIdTag + '"';
            var tagPos = profileJson.IndexOf(qtag);

            if (tagPos < 0)
            {
                return(null);
            }
            var start  = tagPos + qtag.Length + 1;
            var qLeft  = profileJson.IndexOf('"', start);
            var qRight = profileJson.IndexOf('"', qLeft + 1);
            var userId = profileJson.Substring(qLeft + 1, qRight - qLeft - 1);

            return(userId);
        }
Ejemplo n.º 6
0
        public static IOAuthRemoteServer CreateOrUpdateServer(IEntitySession session, string name, OAuthServerOptions options,
                                                              string siteUrl, string authorizationUrl, string tokenRequestUrl, string tokenRefreshUrl,
                                                              string tokenRevokeUrl,
                                                              string scopes, string documentationUrl, string basicProfileUrl, string profileUserIdTag)
        {
            IOAuthRemoteServer srv = session.EntitySet <IOAuthRemoteServer>().Where(s => s.Name == name).FirstOrDefault();

            if (srv == null)
            {
                srv = session.NewEntity <IOAuthRemoteServer>();
            }
            srv.Name             = name;
            srv.Options          = options;
            srv.SiteUrl          = siteUrl;
            srv.AuthorizationUrl = authorizationUrl;
            srv.TokenRequestUrl  = tokenRequestUrl;
            srv.TokenRefreshUrl  = tokenRefreshUrl;
            srv.TokenRevokeUrl   = tokenRevokeUrl;
            srv.Scopes           = scopes;
            srv.DocumentationUrl = documentationUrl;
            srv.BasicProfileUrl  = basicProfileUrl;
            srv.ProfileUserIdTag = profileUserIdTag;
            return(srv);
        }