public AuthenticationResponse Authenticate(string authmethod, ChallengeDetails extra) { if (authmethod == WAMP_CRA) { WampCraChallengeDetails challengeDetails = extra.OriginalValue.Deserialize <WampCraChallengeDetails>(); string signature; if (challengeDetails.Salt == null) { signature = WampCraHelpers.Sign(mAuthenticationKey, challengeDetails.Challenge); } else { signature = WampCraHelpers.AuthSignature(challengeDetails.Challenge, mSecret, challengeDetails); } AuthenticationResponse result = new AuthenticationResponse { Signature = signature }; return(result); } else { throw new WampAuthenticationException("don't know how to authenticate using '" + authmethod + "'"); } }
/// <summary> /// Authenticate the WAMP session to server. /// </summary> /// <param name="proxy">The proxy.</param> /// <param name="formatter">The formatter.</param> /// <param name="authKey">The key of the authentication credentials, something like a user or /// application name.</param> /// <param name="authExtra">Any extra authentication information.</param> /// <param name="authSecret">The secret of the authentication credentials, something like the user /// password or application secret key.</param> /// <returns>The WampCraPermissions.</returns> static WampCraPermissions Authenticate(IWampCraProcedures proxy, IWampFormatter <JToken> formatter, string authKey, IDictionary <string, string> authExtra, string authSecret) { string challenge = proxy.AuthReq(authKey, authExtra); if (string.IsNullOrEmpty(authKey)) { return(proxy.Auth(null)); } WampCraChallenge info = formatter.Deserialize <WampCraChallenge>(JObject.Parse(challenge)); string sig = WampCraHelpers.AuthSignature(challenge, authSecret, info.authextra); return(proxy.Auth(sig)); }
/// <summary> /// RPC endpoint for clients to initiate the authentication handshake. /// </summary> /// <seealso cref="M:WampSharp.Cra.IWampCraProcedures.AuthReq(string,IDictionary{string,string})"/> public string AuthReq(string authKey, IDictionary <string, string> extra) { ValidateAuthReqStatus(authKey); string authSecret = GetAuthReqSecret(authKey); // each authentication request gets a unique authid, which can only be used (later) once! string authid = mIdGenerator.Generate(); //check extra if (extra == null) { extra = new Dictionary <string, string>(); } Dictionary <string, string> extraAuth = new Dictionary <string, string>(extra); WampCraPermissions permissions = GetAuthReqPermissions(authKey, extraAuth); WampCraChallenge info = new WampCraChallenge(authid, authKey, DateTime.UtcNow, mClientSessionId, extra, permissions, extraAuth); mAuthKey = authKey; if (string.IsNullOrEmpty(authKey)) { // anonymous session mPendingAuth = new WampCraPendingAuth(info, null, permissions); return(null); } // authenticated session string infoser = mFormatter.Serialize(info).ToString(); string sig = WampCraHelpers.AuthSignature(infoser, authSecret, info.authextra); mPendingAuth = new WampCraPendingAuth(info, sig, permissions); return(infoser); }