Cortana skill authentication

179 Views Asked by At

I have enabled the connected service in my Cortana channel (Microsoft) and got the token to the BOT framework. Now, I want to retrieve the user details from the token by using the registered client id and secret

Sample code in BOT framework:

var authInfo = ((Activity)context.Activity).Entities.FirstOrDefault(e => e.Type.Equals("AuthorizationToken"));
            var token = authInfo.Properties["token"].ToString();

Any thoughts?

1

There are 1 best solutions below

0
Fracisco Ponce Gomez On

Check BotAuth out. You can retrieve the token choosing a provider:

const botauth = require("botauth");
const DropboxOAuth2Strategy = require("passport-dropbox-oauth2").Strategy;

...

 // Initialize with the strategies we want to use
var auth = new botauth.BotAuthenticator(server, bot, {
    secret : "something secret",
    baseUrl : "https://" + WEBSITE_HOSTNAME }
);

// Configure the Dropbox authentication provider using the passport-dropbox strategy
auth.provider("dropbox",
    function(options) {
        return new DropboxOAuth2Strategy(
            {
                    clientID : DROPBOX_APP_ID,
                    clientSecret : DROPBOX_APP_SECRET,
                    callbackURL : options.callbackURL
            },
            function(accessToken, refreshToken, profile, done) {
                profile.accessToken = accessToken;
                profile.refreshToken = refreshToken;
                done(null, profile);
            }
        );
    }
);

If you just want to retrieve user name and ID you can get it from userData object:

UserInfo : { "Name": { "GivenName": "XYZ", "FamilyName": "ABC" }, "Id": "[email protected]" }

https://github.com/Microsoft/BotBuilder/issues/3242