@exoshtw/apple-auth-backend
Logging with Apple
Last updated 3 months ago by exos .
GPL-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @exoshtw/apple-auth-backend 
SYNC missed versions from official npm registry.

Apple auth for backend

Library for sign in with Apple to use from server-side.

Usage

import fs from 'fs';
import path from 'path';
import {getAuthToken} from '@exoshtw/node-apple-signin';

export function loginApple(code) {
    const response = await getAuthToken(code, {
        clientId: '....',
        teamId: '....',
        keyId: '...',
        key: fs.readFileSync(path.join(__dirname, 'private_key.p8')),
    });

    console.log(response);

    // {
    //   access_token: '...',
    //   token_type: 'Bearer',
    //   expires_in: 3600,
    //   refresh_token: '...',
    //   id_token: '{encoded_jwt_reponse}',
    //   data: { // <- decoded id_token
    //     iss: 'https://appleid.apple.com',
    //     aud: '...',
    //     exp: 1582046751,
    //     iat: 1582046151,
    //     sub: '...',
    //     at_hash: '...',
    //     email: '...',
    //     email_verified: 'true',
    //     auth_time: 1582046132
    //   }
    // }
}

API

{int} getTimestamp()

Get actual timestamp in int32 format.

{string} generateSecret(options)

Generate the JWT signed token for apple auth

Parameters

Name Type Argument Description
options object Options
options.timestamp int optional Timestamp, autogenerated by default
options.expire int optional Expiration time of token
options.clientId string Apple client id
options.teamId string Apple team id
options.keyId string Private key id

{object} getAuthToken(code, options)

Get the auth token to signing with back code

Parameters

Name Type Argument Description
code string Code returned from client app
options object Options
options.timestamp int optional Timestamp, autogenerated by default
options.expire int optional Expiration time of token
options.clientId string Apple client id
options.teamId string Apple team id
options.keyId string Private key id

Motivation

There are other greats libraries (listed bellow) to use with node, but are focused on generating a sign in url and to work with a callback url.

This library is focused on working from the server-side, for example, to use Apple signin from mobile applications.

Other libraries

Current Tags

  • 0.1.0-rc2                                ...           latest (3 months ago)

1 Versions

  • 0.1.0-rc2                                ...           3 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (4)
Dev Dependencies (13)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |